//Page Object
Page({
  data: {
    inputValue: "",
    doingList: [],
    doneList: [],
    isChecked: false,
    doneChecked: true
  },
  handleAdd(e) {
    let info = wx.getStorageSync("userInfo") || {};
    //先把对象转换成数组
    if (Object.keys(info).length === 0) {
      wx.showToast({
        title: '请先登录😡',
        icon: "none"
      });
      return;
    }
    const {
      value
    } = e.detail;
    //判断是不是空字符串，trim()方法去除字符串！两端！空格，无论多少个空格都会去除掉
    //value.trim()若为空，则!value.trim()为true
    if (!value.trim()) {
      wx.showToast({
        title: '不要空白哦😡',
        icon: "none"
      });
      return;
    }
    let List = wx.getStorageSync("doingList") || [];
    List.push(value);
    this.setData({
      doingList: List,
      inputValue: ""
    })
    wx.setStorageSync("doingList", List);
  },
  handleDelete(e) {
    const {
      index
    } = e.currentTarget.dataset;
    let List = wx.getStorageSync("doingList") || [];
    List.splice(index, 1);
    this.setData({
      doingList: List,
    })
    wx.setStorageSync("doingList", List);
  },
  handleDel(e) {
    const {
      index
    } = e.currentTarget.dataset;
    let done = wx.getStorageSync("doneList") || [];
    done.splice(index, 1);
    this.setData({
      doneList: done
    })
    wx.setStorageSync("doneList", done);
  },
  handleChange(e) {
    const {
      index
    } = e.currentTarget.dataset;
    let List = wx.getStorageSync("doingList") || [];
    let done = wx.getStorageSync("doneList") || [];
    done.push(List[index]);
    List.splice(index, 1);
    this.setData({
      doingList: List,
      doneList: done
    })
    wx.setStorageSync("doingList", List);
    wx.setStorageSync("doneList", done);
  },
  handleDoneChecked(e) {
    const {
      index
    } = e.currentTarget.dataset;
    let List = wx.getStorageSync("doingList") || [];
    let done = wx.getStorageSync("doneList") || [];
    List.push(done[index]);
    done.splice(index, 1);
    this.setData({
      doingList: List,
      doneList: done
    })
    wx.setStorageSync("doingList", List);
    wx.setStorageSync("doneList", done);
  },
  //options(Object)
  onLoad: function (options) {

  },
  onReady: function () {

  },
  onShow: function () {
    let List = wx.getStorageSync("doingList") || [];
    let done = wx.getStorageSync("doneList") || [];
    this.setData({
      doingList: List,
      doneList: done
    })
  },
  onHide: function () {

  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {

  },
  onPageScroll: function () {

  },
  //item(index,pagePath,text)
  onTabItemTap: function (item) {

  }
});